<template>
  <el-container>
    <el-header>挂号选择</el-header>
    <el-main>
      <el-row>
        <el-col :span="12">
          <div class="grid-content bg-purple" >
            <el-button type="primary" plain @click="sick = true,sickList(1)" style="width: 200px;height: 100px"><h2>普通挂号</h2></el-button>
          </div>
        </el-col>
        <el-col :span="12">
          <div class="grid-content bg-purple-light">
            <el-button type="success" plain @click="sick = true,sickList(2)" style="width: 200px;height: 100px"><h2>专家挂号</h2></el-button>
          </div>
        </el-col>
      </el-row>
    </el-main>

    <el-main style="margin-top: 10px">
      <el-header>医师推荐</el-header>
      <el-main>
        <div id="biaotou">
          <el-table :data="tableData" stripe style="width:100%" >
            <el-table-column align="center" prop="date" label="日期" width="180" />
            <el-table-column align="center" prop="name" label="姓名" width="180"/>
            <el-table-column align="center" prop="address" label="地址"/>
            <el-table-column align="center" fixed="right" label="操作" width="100px">
              <template slot-scope="scope">
                <el-button @click="open(scope.row)" type="text" size="small">查看</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-main>
    </el-main>

    <el-dialog title="患者列表" :visible.sync="sick" width="680px">
      <center>
        <hr>
        <el-table :data="sickData" height="380" style="width:100%">
          <el-table-column align="center" prop="patientName" label="姓名" width="180px"></el-table-column>
          <el-table-column align="center" prop="patientIdNumber" label="身份证号" width="180px"></el-table-column>
          <el-table-column align="center" prop="patientSex" label="性别" width="180px"></el-table-column>
          <el-table-column align="center" fixed="right" label="操作" width="100px">
            <template slot-scope="scope">
              <el-button @click="sickchoice(scope.row)" type="text" size="small">确定</el-button>
            </template>
          </el-table-column>
        </el-table>
      </center>
      <div slot="footer" class="dialog-footer">
        <el-button @click="sick = false">取 消</el-button>
        <el-button type="primary" @click="sick = false,section = true,departMentList()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="科室" :visible.sync="section" width="500px">
      <center>
        <el-button v-for="(value,i) in departMent" style="width: 120px;margin-top: 10px" @click="departmentchoice(value)">{{value.name}}</el-button>
      </center>
      <div slot="footer" class="dialog-footer">
        <el-button @click="section = false">取 消</el-button>
        <el-button type="primary" @click="opendoctor(),section = false">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog title="医生" :visible.sync="doctor" width="680px">
      <center>
        <el-row>
          <el-col :span="21">
            <div class="grid-content bg-purple">
              <el-input placeholder="请输入医生姓名" v-model="doctorName" clearable/>
            </div>
          </el-col>
          <el-col :span="3">
            <div class="grid-content bg-purple">
              <el-button type="primary" icon="el-icon-search">搜索</el-button>
            </div>
          </el-col>
        </el-row>
      <hr>
        <el-table :data="tableData" height="380" style="width:100%">
          <el-table-column align="center" prop="name" label="姓名" width="180px"></el-table-column>
          <el-table-column align="center" prop="registrationFee" label="费用" width="180px"></el-table-column>
          <el-table-column align="center" prop="state" label="科室" width="180px"></el-table-column>
          <el-table-column align="center" fixed="right" label="操作" width="100px">
            <template slot-scope="scope">
              <el-button @click="open(scope.row)" type="text" size="small">查看</el-button>
              <el-button @click="open(scope.row)" type="text" size="small">确定</el-button>
            </template>
          </el-table-column>
        </el-table>
      </center>
      <div slot="footer" class="dialog-footer">
        <el-button @click="doctor = false">取 消</el-button>
        <el-button type="primary" @click="doctor = false">确 定</el-button>
      </div>
    </el-dialog>
  </el-container>
</template>

<script>
import request from "@/utils/request";

export default {
  data() {
    return {
      //科室弹框开关
      section: false,
      doctor: false,
      sick:false,
      //挂号类别
      kind:0,
      doctorName:"",
      departMent:[],
      sickData:[],
      registration:{
        registrationOffice:0,
        registrationDoctorId:0,
        registrationSickId:0
      },
      tableData:[]
    }
  },
  methods: {
    //医生详细显示
    open(aa) {
      this.$alert('<strong>姓名：<i>'+aa.name+'</i></strong><br>'+
        '<strong>科室：<i>xxx</i></strong><br>'+
        '<strong>详情：<i>'+aa.description+'</i></strong>'
        ,
        '医生介绍',
        {
        dangerouslyUseHTMLString: true
      });
    },
    //科室列表
    departMentList(){
      return request({
        url: '/lha/department/findAll',
        method: 'get'
      }).then(res => {
        this.departMent=res.data;
        console.log(res)
      }).catch()
    },
    //患者列表
    sickList(a){
      this.kind=a;
      return request({
        url: '/lha/sick/findAlla',
        method: 'get'
      }).then(res => {
        this.sickData=res.data;
        console.log(res)
      }).catch()
    },
    //科室选择
    departmentchoice(a){
      this.registration.registrationOffice=a.departmentId;
      console.log(this.registration.registrationOffice)
      this.$message('你选择了'+a.name);
    },
    //患者选择
    sickchoice(a){
      this.registration.registrationSickId=a.patientId;
      this.$message('你选择了'+a.patientName);
    },
    //打开医生选择
    opendoctor(){
      if(this.kind==1){
        this.$confirm('确定科室，随机普通挂号?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
        }).then(() => {
          this.$message({
            type: 'success',
            message: '挂号已创建成功，请到挂号详情查看并10钟内支付!'
          });
          this.generateRegistration();
        });
      }else if(this.kind==2) {
        this.doctor = true;
        return request({
          url: '/lha/doctor/findAll/' + this.registration.registrationOffice,
          method: 'get'
        }).then(res => {
          console.log("医生")
          this.tableData = res.data;
          console.log(res)
        }).catch()
      }
    },
    //生成挂号单对象
    generateRegistration(){
      return request({
        url: '/lha/registration/addRecord',
        method: 'post',
        data: this.registration
      }).then(res => {
        sessionStorage.setItem("rediskey",res.data)
      }).catch()
    }
  }
}
</script>

<style lang="less" scoped>
.el-row {
  margin-bottom: 0px;
}
.el-col {
  border-radius: 4px;
}
.bg-purple {
  background: #f4f5f6;
}
.bg-purple-light {
  background: #f4f5f6;
}
.grid-content {
  border-radius: 4px;
  min-height: 36px;
}
.el-main {
  background-color: #E9EEF3;
  color: #333;
  text-align: center;
  line-height: 160px;
}
.el-header, .el-footer {
  background-color: #f5f9fd;
  color: #333;
  text-align: center;
  line-height: 60px;
}
#biaotou {
    width: 100%;
    height: 100%;
  /deep/ .el-table__header tr,
  //修改th表头高度
    .el-table__header th {
      padding: 0;
      height: 30px;
      line-height: 30px;
    }
  /deep/ .el-table__body tr,
  .el-table__body td {//修改td单元格高度
  padding: 0;
    height: 30px;
    line-height: 30px;
  }
}
</style>

